public class MinSubArrayLen {
    public static int minSubArrayLen(int target, int[] nums) {
        int n=nums.length;
        int min=n+1;
        int left=0;
        int sum=0;
        for (int i = 0; i < n; i++) {
            sum+=nums[i];
            while (sum>=target){
                min=Math.min(min,i-left+1);//(i+1)-left  个数
                sum-=nums[left++];
            }
        }
        return min==n+1?0:min;
    }

    public static void main(String[] args) {
        int [] nums={2,3,1,2,4,3};
        System.out.println(minSubArrayLen(7,nums));
//        int [] nums={1,4,4};
//        System.out.println(minSubArrayLen(3,nums));
    }

}
